
*12345678901234567890123456789012345678901234567890123456789012345678901234567890
capture log close
clear all
set more off

*	************************************************************************
* 	File-Name: 	AccessOffGridAnalysis.do
*	Log-file:	na
*	Date:  		07/20/2019
*	Author: 	Michaël Aklin and Johannes Urpelainen
*	Data Used:  various
*	Output		na
*	Purpose:   	.do file for the analysis of off-grid/ACCESS-2 project
*	************************************************************************

*	************************************************************************
* 	A.0 Data
*	************************************************************************

clear all
cd "ADD_PATH_TO_REPLICATION_FILE_HERE"

quiet do "AccessOffGridCoding.do"
keep if panel_flag == 1 // Only keep panel observations

xtset hhid wave


*	************************************************************************
* 	B. Analysis
*	************************************************************************

*	************************************************************************
* 	B.1. Summary stats and claims made in the manuscript
*	************************************************************************


estpost sum own_*, d
esttab using "./ss_light_own.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear
	
estpost sum own_* if year == 2015, d
esttab using "./ss_light_own2015.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear
	
estpost sum own_* if year == 2018, d
esttab using "./ss_light_own2018.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear

estpost sum primary_*, d
esttab using "./ss_light_primary.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear
	
estpost sum primary_* if year == 2015, d
esttab using "./ss_light_primary2015.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear
	
estpost sum primary_* if year == 2018, d
esttab using "./ss_light_primary2018.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear

estpost sum m2_q68_elec saubhagya mean_grid mean_hours m2_q69_elec_hrs m1_q32_month_expenditure logexp female m1_q19_age, d
esttab using "./ss_general.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear

estpost sum m2_q68_elec saubhagya mean_grid mean_hours m2_q69_elec_hrs m1_q32_month_expenditure logexp female m1_q19_age if year == 2015, d
esttab using "./ss_general2015.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear

estpost sum m2_q68_elec saubhagya mean_grid mean_hours m2_q69_elec_hrs m1_q32_month_expenditure logexp female m1_q19_age if year == 2018, d
esttab using "./ss_general2018.tex", ///
	cells("mean(label(Mean) fmt(3)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
eststo clear

*	************************************************************************
* 	B.2 Analysis
*	************************************************************************

tab m2_q58_micro_use
tab m2_q58_micro_use if year == 2015
tab m2_q58_micro_use if year == 2018

tab micro_v2
tab micro_v2 if year == 2015
tab micro_v2 if year == 2018

tab shslanterns_v2
tab shslanterns_v2 if year == 2015
tab shslanterns_v2 if year == 2018


cor micro_v2 shslanterns_v2 m2_q55_grid
cor micro_v2 shslanterns_v2 m2_q55_grid if year == 2015
cor micro_v2 shslanterns_v2 m2_q55_grid if year == 2018

*	************************************************************************
* 	Overview
*	************************************************************************

eststo m1: xtreg own_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m2: xtreg primary_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo m3: xtreg own_shs wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m4: xtreg primary_shs wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo m5: xtreg own_dieselmg wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m6: xtreg primary_dieselmg wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo m7: xtreg own_solarmg wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m8: xtreg primary_solarmg wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo m9: xtreg own_solarlantern wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m10: xtreg primary_solarlantern wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo m11: xtreg own_kerosenelantern wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m12: xtreg primary_kerosenelantern wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

esttab using "./reg_village_summary.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2, fmt(0 0 2) ///
    labels("HH fixed effects" "Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("Grid" "SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Use" "Own" "Use" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels

*	Figure 3
coefplot (m1, label("Own")) (m2, label("Primary use")), bylabel("Grid")   ///
		|| (m3) (m4), bylabel("SHS")   ///
		|| (m5) (m6), bylabel("Diesel MG")  ///
		|| (m7) (m8) , bylabel("Solar MG")  ///
		|| (m9) (m10), bylabel("Solar lantern")  ///
		|| (m11) (m12), bylabel("Kerosene lantern")  ///
		||	///
			, 	///
			rescale(100) ///
			keep(wave) ///
			xline(0) ///
			ytitle(" ") ///
			xtitle("Marginal effect of time, 2015-2018 (percentage points)")	///
			bycoefs ///
			legend(position(6) row(1)) ysize(3)
graph export "./coefplot_time.pdf", replace as(pdf) 
eststo clear

*	************************************************************************
* 	SHS (own and primary)
*	************************************************************************

*	Ownership
eststo: xtreg own_shs wave, fe cluster(hhid)
	quiet sum `e(depvar)' if e(sample) == 1 & year == 2015
	estadd scalar Outcome_Mean_2015 =`r(mean)'
	quiet sum own_shs if e(sample) == 1
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed_2015 "$\checkmark$" , replace
eststo: xtreg own_shs wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdown_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
	quiet sum fdown_shs if e(sample) == 1
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdown_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_own_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
	quiet sum fgain_own_shs if e(sample) == 1
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_own_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_own_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
	quiet sum floss_own_shs if e(sample) == 1
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_own_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_own_shs.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean_2015 Outcome_Mean, fmt(0 0 3 2 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean in 2015" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("SHS ($=$1)" "$\Delta$ SHS" "SHS Gain ($=$1)" "SHS Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	Usage
eststo: xtreg primary_shs wave, fe cluster(hhid)
	quiet sum `e(depvar)' if e(sample) == 1 & year == 2015
	estadd scalar Outcome_Mean_2015 =`r(mean)'
	quiet sum primary_shs if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg primary_shs wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdprimary_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
	quiet sum fdprimary_shs if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdprimary_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_primary_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
	quiet sum fgain_primary_shs if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_primary_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_primary_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
	quiet sum floss_primary_shs if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_primary_shs fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_primary_shs.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean_2015 Outcome_Mean, fmt(0 0 3 2 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean in 2015" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("SHS ($=$1)" "$\Delta$ SHS" "SHS Gain ($=$1)" "SHS Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear




*	************************************************************************
* 	Diesel microgrid (own and primary)
*	************************************************************************

*	Ownership
eststo: xtreg own_dieselmg wave, fe cluster(hhid)
  quiet sum own_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg own_dieselmg wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdown_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdown_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdown_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_own_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_own_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_own_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_own_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum floss_own_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_own_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_own_dieselmg.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean, fmt(0 0 3 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Diesel MG ($=$1)" "$\Delta$ Diesel MG" "Diesel MG Gain ($=$1)" "Diesel MG Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	Usage
eststo: xtreg primary_dieselmg wave, fe cluster(hhid)
  quiet sum primary_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg primary_dieselmg wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdprimary_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdprimary_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdprimary_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_primary_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_primary_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_primary_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_primary_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum floss_primary_dieselmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_primary_dieselmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_primary_dieselmg.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean, fmt(0 0 3 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Diesel MG ($=$1)" "$\Delta$ Diesel MG" "Diesel MG Gain ($=$1)" "Diesel MG Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear


*	************************************************************************
* 	Solar microgrid (own and primary)
*	************************************************************************

*	Ownership
eststo: xtreg own_solarmg wave, fe cluster(hhid)
  quiet sum own_solarmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg own_solarmg wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdown_solarmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdown_solarmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdown_solarmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_own_solarmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_own_solarmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_own_solarmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_own_solarmg.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean, fmt(0 0 3 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Solar MG ($=$1)" "$\Delta$ Solar MG" "Solar MG Gain ($=$1)", pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	Usage
eststo: xtreg primary_solarmg wave, fe cluster(hhid)
  quiet sum primary_solarmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg primary_solarmg wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdprimary_solarmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdprimary_solarmg if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdprimary_solarmg fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_primary_solarmg.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean, fmt(0 0 3 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Solar MG ($=$1)" "$\Delta$ Solar MG", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear


*	************************************************************************
* 	Solar lantern (own and primary)
*	************************************************************************

*	Ownership
eststo: xtreg own_solarlantern wave, fe cluster(hhid)
	quiet sum `e(depvar)' if e(sample) == 1 & year == 2015
	estadd scalar Outcome_Mean_2015 =`r(mean)'
	quiet sum own_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg own_solarlantern wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdown_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdown_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdown_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_own_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_own_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_own_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_own_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum floss_own_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_own_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_own_solarlantern.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean_2015 Outcome_Mean, fmt(0 0 3 2 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean in 2015" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Solar Lantern ($=$1)" "$\Delta$ Solar Lantern" "Solar Lantern Gain ($=$1)" "Solar Lantern Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	Usage
eststo: xtreg primary_solarlantern wave, fe cluster(hhid)
	quiet sum `e(depvar)' if e(sample) == 1 & year == 2015
	estadd scalar Outcome_Mean_2015 =`r(mean)'
	quiet sum primary_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg primary_solarlantern wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdprimary_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdprimary_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdprimary_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_primary_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_primary_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_primary_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_primary_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum floss_primary_solarlantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_primary_solarlantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_primary_solarlantern.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean_2015 Outcome_Mean, fmt(0 0 3 2 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean in 2015" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Solar Lantern ($=$1)" "$\Delta$ Solar Lantern" "Solar Lantern Gain ($=$1)" "Solar Lantern Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear


*	************************************************************************
* 	Kerosene lantern (own and primary)
*	************************************************************************


*	Ownership
eststo: xtreg own_kerosenelantern wave, fe cluster(hhid)
  quiet sum own_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg own_kerosenelantern wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdown_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdown_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdown_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_own_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_own_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_own_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_own_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum floss_own_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_own_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_own_kerosenelantern.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean, fmt(0 0 3 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Kerosene Lantern ($=$1)" "$\Delta$ Kerosene Lantern" "Kerosene Lantern Gain ($=$1)" "Kerosene Lantern Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	Usage
eststo: xtreg primary_kerosenelantern wave, fe cluster(hhid)
  quiet sum primary_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
	estadd local fixed "$\checkmark$" , replace
eststo: xtreg primary_kerosenelantern wave logexp own_grid i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

eststo: reg fdprimary_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fdprimary_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fdprimary_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg fgain_primary_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum fgain_primary_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg fgain_primary_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

eststo: reg floss_primary_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste, cluster(districtid)
  quiet sum floss_primary_kerosenelantern if e(sample)
	estadd scalar Outcome_Mean=`r(mean)'
eststo: reg floss_primary_kerosenelantern fdown_grid logexp i.m1_q23_edu female m1_q19_age ib4.m1_q25_caste i.districtid, cluster(districtid)
	estadd local distfixed "$\checkmark$" , replace

esttab using "./reg_primary_kerosenelantern.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2 Outcome_Mean, fmt(0 0 3 2 2) ///
    labels("Household FE" "Observations" "$ R^2$" "Outcome mean")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	substitute(m$ m\\$)	///
	mgroups("Kerosene Lantern ($=$1)" "$\Delta$ Kerosene Lantern" "Kerosene Lantern Gain ($=$1)" "Kerosene Lantern Loss ($=$1)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear



*	************************************************************************
* 	Saughabya
*	************************************************************************

egen own_sum = rowtotal(own_grid own_shs own_dieselmg own_solarmg ///
	own_solarlantern own_kerosenelantern), missing
tab own_sum

eststo: reg own_grid saubhagya if l.own_grid == 0, cluster(districtid)
eststo m1: reg own_grid saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg own_shs saubhagya if l.own_grid == 0, cluster(districtid)
eststo m2: reg own_shs saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg own_dieselmg saubhagya if l.own_grid == 0, cluster(districtid)
eststo m3: reg own_dieselmg saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg own_solarmg saubhagya if l.own_grid == 0, cluster(districtid)
eststo m4: reg own_solarmg saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg own_solarlantern saubhagya if l.own_grid == 0, cluster(districtid)
eststo m5: reg own_solarlantern saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg own_kerosenelantern saubhagya if l.own_grid == 0, cluster(districtid)
eststo m6: reg own_kerosenelantern saubhagya i.districtid if l.own_grid == 0, cluster(districtid)

esttab using "./reg_own_saubhagya.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(N r2, fmt(0 2) ///
    labels("Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("Grid" "SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

eststo: reg primary_grid saubhagya if l.own_grid == 0, cluster(districtid)
eststo m1b: reg primary_grid saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg primary_shs saubhagya if l.own_grid == 0, cluster(districtid)
eststo m2b: reg primary_shs saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg primary_dieselmg saubhagya if l.own_grid == 0, cluster(districtid)
eststo m3b: reg primary_dieselmg saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg primary_solarlantern saubhagya if l.own_grid == 0, cluster(districtid)
eststo m5b: reg primary_solarlantern saubhagya i.districtid if l.own_grid == 0, cluster(districtid)
eststo: reg primary_kerosenelantern saubhagya if l.own_grid == 0, cluster(districtid)
eststo m6b: reg primary_kerosenelantern saubhagya i.districtid if l.own_grid == 0, cluster(districtid)

esttab using "./reg_primary_saubhagya.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(N r2, fmt(0 2) ///
    labels("Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("Grid" "SHS" "Diesel MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	nomtitles	///
	indicate("District FE = *districtid*", label($\checkmark$ ))	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	Figure 4
* Note: need to run the previous manually (because of eststo clear)
coefplot (m1, label("Own")) (m1b, label("Primary use")), bylabel("Grid")   ///
		|| (m2) (m2b), bylabel("SHS")   ///
		|| (m3) (m3b), bylabel("Diesel MG")  ///
		|| (m4) , bylabel("Solar MG")  ///
		|| (m5) (m5b), bylabel("Solar lantern")  ///
		|| (m6) (m6b), bylabel("Kerosene lantern")  ///
		||	///
			, 	///
			keep(saubhagya) ///
			xline(0) ///
			rescale(100) ///
			ytitle(" ") ///
			xtitle("Marginal effect of Saubhagya (percentage points)")	///
			bycoefs ///
			legend(position(6) row(1))
graph export "./coefplot_saubhagya.pdf", replace as(pdf) 
eststo clear

*	************************************************************************
* 	B.3. Graphs
*
*		See R file for other graphs.
*	************************************************************************

tab dist_lighting_group
tab dist_lighting_group if year == 2015
tab dist_lighting_group if year == 2018

graph hbar (count) 	///
	, 	///
	over(dist_lighting_group, sort(1))	///
	blabel(bar, position(outside) format(%9.0f))	///
	ytitle("Number of households")
graph export "./bar_group.pdf", replace as(pdf) 
	
	
catplot m3_q85_light_main_satisfy dist_lighting_group	///
	,	/// 
	 stack asyvars	///
	ytitle("Households (%)")	///
	legend(position(6) row(1)) 	///
	percent(dist_lighting_group) var2opts(sort(1) )	///
	legend(position(6) row(1)) blabel(bar, position(center) format(%9.1f))	
graph export "./cat_satlighting_group_pct_v2.pdf", replace as(pdf) 

catplot m3_q85_light_main_satisfy dist_lighting_group	///
	,	/// 
	 stack asyvars	///
	ytitle("Households (count)")	///
	legend(position(6) row(1)) 	///
	 var2opts(sort(1) )	///
	legend(position(6) row(1))	 blabel(total, position(outside) format(%9.0f))	
graph export "./cat_satlighting_group_count_v2.pdf", replace as(pdf) 



*	************************************************************************
* 	C. Appendix
*	************************************************************************

*	************************************************************************
* 	Village-level controls: grid
*	************************************************************************

xtset hhid wave
eststo m1: xtreg own_grid mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m2: xtreg primary_grid mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m3: xtreg own_shs mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m4: xtreg primary_shs mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m5: xtreg own_dieselmg mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m6: xtreg primary_dieselmg mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m7: xtreg own_solarmg mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m8: xtreg own_solarlantern mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m9: xtreg primary_solarlantern mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m10: xtreg own_kerosenelantern mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m11: xtreg primary_kerosenelantern mean_grid wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

esttab using "./reg_village_meangrid.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2, fmt(0 0 2) ///
    labels("HH fixed effects" "Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("Grid" "SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels

coefplot (m3, label("Own")) (m4, label("Primary use")), bylabel("SHS")   ///
		|| (m5) (m6), bylabel("Diesel MG")  ///
		|| (m7) , bylabel("Solar MG")  ///
		|| (m8) (m9), bylabel("Solar lantern")  ///
		|| (m10) (m11), bylabel("Kerosene lantern")  ///
		||	///
			, 	///
			keep(mean_grid) ///
			xline(0) ///
			rescale(100) ///
			ytitle(" ") ///
			xtitle("Marginal effect of mean grid (percentage points)")	///
			bycoefs ///
			legend(position(6) row(1))
graph export "./coefplot_meangrid.pdf", replace as(pdf) 
eststo clear

*	************************************************************************
* 	Village-level controls: hours
*	************************************************************************

eststo m1: xtreg own_shs mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m2: xtreg primary_shs mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m3: xtreg own_dieselmg mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m4: xtreg primary_dieselmg mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m5: xtreg own_solarmg mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m6: xtreg own_solarlantern mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m7: xtreg primary_solarlantern mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m8: xtreg own_kerosenelantern mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace
eststo m9: xtreg primary_kerosenelantern mean_hours wave logexp i.m1_q23_edu, fe cluster(hhid)
	estadd local fixed "$\checkmark$" , replace

esttab using "./reg_village_meanhours.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N r2, fmt(0 0 2) ///
    labels("HH fixed effects" "Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels

coefplot (m1, label("Own")) (m2, label("Primary use")), bylabel("SHS")   ///
		|| (m3) (m4), bylabel("Diesel MG")  ///
		|| (m5) , bylabel("Solar MG")  ///
		|| (m6) (m7), bylabel("Solar lantern")  ///
		|| (m8) (m9), bylabel("Kerosene lantern")  ///
		||	///
			, 	///
			keep(mean_hours) ///
			xline(0) ///
			rescale(100) ///
			ytitle(" ") ///
			xtitle("Marginal effect of grid hours (percentage points)")	///
			bycoefs ///
			legend(position(6) row(1))
graph export "./coefplot_meanhours.pdf", replace as(pdf) 
eststo clear

*	************************************************************************
* 	Village-level controls: Saughabya (max)
*	************************************************************************

eststo: reg own_shs max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_shs max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_dieselmg max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_dieselmg max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarmg max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarlantern max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_solarlantern max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_kerosenelantern max_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_kerosenelantern max_saubhagya logexp i.m1_q23_edu, cluster(hhid)

esttab using "./reg_village_maxsaubhagya.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(N r2, fmt(0 2) ///
    labels("Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear


eststo: reg own_shs max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_shs max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_dieselmg max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_dieselmg max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarmg max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarlantern max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_solarlantern max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_kerosenelantern max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_kerosenelantern max_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)

esttab using "./reg_village_maxsaubhagya_controls.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(N r2, fmt(0 2) ///
    labels("Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	************************************************************************
* 	Village-level controls: Saughabya (mean)
*	************************************************************************

eststo: reg own_shs mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_shs mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_dieselmg mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_dieselmg mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarmg mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarlantern mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_solarlantern mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_kerosenelantern mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_kerosenelantern mean_saubhagya logexp i.m1_q23_edu, cluster(hhid)

esttab using "./reg_village_meansaubhagya.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(N r2, fmt(0 2) ///
    labels("Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear


eststo: reg own_shs mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_shs mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_dieselmg mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_dieselmg mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarmg mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_solarlantern mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_solarlantern mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg own_kerosenelantern mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)
eststo: reg primary_kerosenelantern mean_saubhagya logpop c01_2001_dist_town c11_2011_pucca_road logexp i.m1_q23_edu, cluster(hhid)

esttab using "./reg_village_meansaubhagya_controls.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(N r2, fmt(0 2) ///
    labels("Observations" "$ R^2$")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	************************************************************************
* 	Multi-level model: main
*	************************************************************************

preserve

xtset hhid wave
eststo m1a: meglm own_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m2b: meglm primary_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m1: meglm own_shs wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m2: meglm primary_shs wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m3: meglm own_dieselmg wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m4: meglm primary_dieselmg wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m5: meglm own_solarmg wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m6: meglm primary_solarmg wave logexp i.m1_q23_edu || m1_q9_district_code:
 	estadd local fixed "$\checkmark$" , replace
eststo m7: meglm own_solarlantern wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m8: meglm primary_solarlantern wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m9: meglm own_kerosenelantern wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo m10: meglm primary_kerosenelantern wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace

esttab using "./reg_village_multilevel.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N, fmt(0 0 2) ///
    labels("Random effects" "Observations")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("Grid" "SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Use" "Own" "Use" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
// eststo clear

coefplot (m1a, label("Own")) (m2b, label("Use")), bylabel("Grid")   ///
		|| (m1) (m2), bylabel("SHS")   ///
		|| (m3) (m4), bylabel("Diesel MG")  ///
		|| (m5) (m6), bylabel("Solar MG")  ///
		|| (m7) (m8), bylabel("Solar lantern")  ///
		|| (m9) (m10), bylabel("Kerosene lantern")  ///
		||	///
			, 	///
			keep(wave) ///
			xline(0) ///
			ytitle(" ") ///
			xtitle("Marginal effect of three-year period")	///
			bycoefs ///
			legend(position(6) row(1))
graph export "./coefplot_hierarchical_wave.pdf", replace as(pdf) 
eststo clear
restore


			

*	************************************************************************
* 	Multi-level model: mean grid
*	************************************************************************

xtset hhid wave
eststo: meglm own_shs mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_shs mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_dieselmg mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_dieselmg mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_solarmg mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
eststo: meglm own_solarlantern mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_solarlantern mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_kerosenelantern mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_kerosenelantern mean_grid wave logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace

esttab using "./reg_village_meangrid_multilevel.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N, fmt(0 0 2) ///
    labels("Random effects" "Observations")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear

*	************************************************************************
* 	Multilevel model: mean Saubhagya
*	************************************************************************

eststo: meglm own_shs mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_shs mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_dieselmg mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_dieselmg mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_solarmg mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_solarlantern mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_solarlantern mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm own_kerosenelantern mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace
eststo: meglm primary_kerosenelantern mean_saubhagya logexp i.m1_q23_edu || m1_q9_district_code:
	estadd local fixed "$\checkmark$" , replace

esttab using "./reg_village_meansaubhagya_multilevel.tex"	///
	, 	booktabs label replace ///
 	nodepvars se(3) b(3) ///
	stats(fixed N, fmt(0 0 2) ///
    labels("Random effects" "Observations")) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("SHS" "Diesel MG" "Solar MG" "Solar lantern" "Kerosene lantern", pattern(1 0 1 0 1 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	mtitles("Own" "Use" "Own" "Use" "Own" "Own" "Use" "Own" "Use" )	///
	noconstant eqlabels(none) nonotes nobaselevels
eststo clear





